package com.pengxun.mall.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import  com.pengxun.mall.dto.GoodsDTO;
import  com.pengxun.mall.dto.GoodsSearchDTO;
import  com.pengxun.mall.service.GoodsService;
import  com.pengxun.mall.vo.GoodsVO;
import com.szeastroc.common.jdbc.page.Page;
import com.szeastroc.common.result.Result;
import com.szeastroc.common.result.ResultUtils;


@RestController
@RequestMapping("/goods")
public class  GoodsController{

   @Resource
   private GoodsService goodsService;
   
   
   @RequestMapping("/insert")
   public Result<Object> insert(@RequestBody GoodsDTO goodsDTO){
       goodsService.insert(goodsDTO);    
	   return ResultUtils.render();
   }
   
   @RequestMapping("/update")
   public Result<Object> update(@RequestBody GoodsDTO goodsDTO){
      goodsService.update(goodsDTO);
	   return ResultUtils.render();
   }
   
   @RequestMapping("/delete")
   public Result<Object> delete(Integer id){
       goodsService.delete(id);
	   return ResultUtils.render();
   }
   
   @RequestMapping("/findById")
   public Result<Object> findById(Integer id) {
		return ResultUtils.render(goodsService.findById(id));
	}
	
   @RequestMapping("/findAll")
   public Result<Object> findAll() {
		List<GoodsVO> goodsVOs = goodsService.findAll();
		return ResultUtils.render(goodsVOs);
	}
	
   @RequestMapping("/findByPage")
   public Result<Object> findByPage(@RequestBody GoodsSearchDTO goodsSearchDTO) {
	    Page page =  goodsService.findByPage(goodsSearchDTO);
		return ResultUtils.render(page);
	}
}
